package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class ButtonActivity extends AppCompatActivity {

    private TextView timeView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_button);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        timeView = findViewById(R.id.time_view);

        findViewById(R.id.jumpToFirst).setOnClickListener(view->{

            Intent intent = new Intent(this, MainActivity.class);
            // 栈中存在待跳转的 activity 时，则重新创建该实例，
            // 并清除原实例上方的所有实例
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            startActivity(intent);
        });

    }

    public void refreshTime(View view) {

        String text = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) + ":您点击了 " + ((Button) view).getText();


        timeView.setText(text);
    }
}